<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>请假审批</title>
		<meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
	    <link rel="stylesheet" href="../../css/public.css" media="all">
	</head>
	<body>
	<div class="layuimini-container">
	    <div class="layuimini-main">	
			<!--表格开始-->
	        <table class="layui-hide" id="loginfoTable" lay-filter="loginfoTable"></table>
			<script type="text/html" id="loginfoTableBar">
				<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="yes">审批同意</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="no">审批拒绝</a>
			</script>
			
			<!--表格结束-->
	    </div>
	</div>
	<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
	<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
	<script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
	<script src="../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
	<!-- 前后端分离 -->
	<script src="../../lib/common/common.js" charset="utf-8"></script>
	
	<script>
	    layui.use(['form', 'table','layer'], function () {
	        var form = layui.form;
	        var table = layui.table;
			var layer=layui.layer;
	
	      var tableIns=table.render({
	            elem: '#loginfoTable',
	            url: api+"leave/ExamineAndApprove",
				toolbar:"#loginfoToolBar",
				cellMinWidth:true,
	            cols: [ [
	                {field: 'activitiId', title: '请假id', align: "center",width: 120},
					{field: 'processInstans',  title: '流程id', align: "center",width: 140},
	                {field: 'days',  title: '请假天数', align: "center",width: 140},
					{field: 'content',  title: '请假原因', align: "center",width: 360},
					{field: 'createTime',  title: '创建时间', align: "center",width: 200},
					{field: 'username',  title: '请假人', align: "center",width: 140},
					{field: 'state',  title: '状态', align: "center",width: 140,templet: function(d){
						var html="";
						if(d.state == 1){
							html="<font color=red>提交</font>"
						}else if(d.state == 2){
							html="<font color=black>审批中</font>"
						}else if(d.state == 3){
							html="<font color=blue>审批通过</font>"
						}else if(d.state == 4){
							html="<font color=blue>审批失败</font>"
						}
						return html;
					}},
	                {title: '操作', templet: '#loginfoTableBar', fixed: "right", align: "center",width: 250}
	            ] ],
	            page: true,
	        });
	
			//监听表头的事件
			table.on('toolbar(loginfoTable)', function(obj){
			  var checkStatus = table.checkStatus(obj.config.id);
			  switch(obj.event){
			    case 'batchdelete':
					var checkStatus = table.checkStatus('loginfoTable'); //idTest 即为基础参数 id 对应的值
					var data=checkStatus.data;
					var length=checkStatus.data.length;
					console.log(checkStatus.data) //获取选中行的数据
					console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
					if(length==0){
						layer.msg("请选中要删除的行数据");
					}else{
						layer.confirm('真的删除选择中这些数据么?', function (index) {
							var params="";
							$.each(data,function(index,item){
								if(index==0){
									params+="ids="+item.activitiId;
									params+="pids="+item.processInstans;
								}else{
									params+="&ids="+item.activitiId;
									params+="&pids="+item.processInstans;
								}
							});
							$.post(api+"leave/DeletelEAVE",params,function(res){
								layer.msg(res.msg);
								tableIns.reload();
								layer.close(index);
							})
						});
					}
			        //layer.msg('批量删除');
			    break;
			  };
			});
			
			//监听行数据的事件
			table.on('tool(loginfoTable)', function (obj) {
				var data = obj.data;
				if (obj.event === 'delete') {
					layer.confirm('真的删除这条数据么', function (index) {
						$.post(api+"leave/DeletelEAVE",{ids:data.activitiId,pids:data.processInstans},function(res){
							layer.msg(res.msg);
							obj.del();
							layer.close(index);
						})
					});
				}else if(obj.event === 'yes'){
					$.post(api+"leave/ApprovalTask",{ids:data.activitiId,pids:data.processInstans,type:"yes"},function(res){
						layer.msg(res.msg);
						obj.del();
						layer.close(index);
					})
				}else if(obj.event === 'no'){
					$.post(api+"leave/ApprovalTask",{ids:data.activitiId,pids:data.processInstans,type:"no"},function(res){
						layer.msg(res.msg);
						obj.del();
						layer.close(index);
					})
				}
				
			});			
			
	    });
	</script>
	</body>
	</html>